
package com.fricano.java42.swing.dings.tester;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTree;
import javax.swing.JWindow;

import com.fricano.java42.base.components.factory.Factory_Image;
import com.fricano.java42.base.components.factory.Factory_Swing;
import com.fricano.java42.base.components.helper.Helper_Swing;
import com.fricano.java42.swing.dings.components.J42JPanel_Slidable;

public class J42SwingDing_PanelSliderTest_01 {

    static public void main(final String[] args) throws Exception {

        if (true) {

            final JFrame frame = new JFrame("JFrame");
            frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

            final JDialog dialog = new JDialog((JDialog) null, "JDialog");
            dialog.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

            final JWindow window = new JWindow();

            //final JFrame owner = frame;
            final JDialog owner = dialog;
            //final JWindow owner = window;

            final J42JPanel_Slidable slider;
            slider = new J42JPanel_Slidable(owner);

            {
                //slider = new J42JPanel_Slidable<>(jFrame.getContentPane());
                //slider = new J42JPanel_Slidable<>(jFrame.getRootPane().getTopLevelAncestor());
                // CROSSFADE NOT SUPPORTED
                //slider = new J42JPanel_Slidable(jFrame.getContentPane());
            }

            slider.getManager().addDevelopmentControls();
            slider.getManager().setTransitionStyle(500, J42JPanel_Slidable.Style.SLIDE);
            slider.getManager().setTransitionStyle(500, J42JPanel_Slidable.Style.CROSSFADE);

            final JTree jTree1 = new JTree();
            final JTree jTree2 = new JTree();
            slider.getManager().addComponent(jTree1);
            slider.getManager().addComponent(new JButton("AAAAAAAAAAAAA"));
            slider.getManager().addComponent(new JButton("ZZZZZZZZZZZZZZZZZZZZZZZZZ"));

            //            slider.add(new JButton("10000000001"));
            //            final JButton h77 = new JButton("100077770000001");
            //slider.getManager().addComponent(h77);
            //slider.getManager().removeComponent(h77);
            //slider.add(h77);
            //slider.remove(h77);

            //            slider.getManager().addComponent(jTree1);
            //            slider.getManager().addComponent(jTree2);
            //            slider.getManager().addComponent(new JButton("33"));
            //            slider.getManager().addComponent(new JButton("44"));
            //            slider.getManager().addComponent(new JButton("55"));
            //            slider.getManager().addComponent(new JButton("66"));
            //            slider.getManager().addComponent(new JLabel(Factory_Image.getInstance().createTestIcon(200, true)));
            //            slider.getManager().addComponent(new JLabel(Factory_Image.getInstance().createTestIcon(200, false)));
            //            slider.getManager().addComponent(new JLabel(new ImageIcon(Factory_Image.getInstance().createTestImage(200))));
            //            slider.getManager().addComponent(new JLabel(new ImageIcon(Factory_Image.getInstance().createTestImage(200, true))));
            //            slider.getManager().addComponent(new JLabel(new ImageIcon(Factory_Image.getInstance().createTestImage(200, false))));

            //            final JButton southButton = new JButton("SlideTo JTree");
            //            southButton.addActionListener(new ActionListener() {
            //                @Override
            //                public void actionPerformed(final ActionEvent e) {
            //                    slider.getManager().slideTo(jTree);
            //                }
            //            });

            //            if (false) {
            //                owner.setLayout(new BorderLayout(2, 2));
            //                owner.getContentPane().add(new JButton("N"), BorderLayout.NORTH);
            //                owner.getContentPane().add(southButton, BorderLayout.SOUTH);
            //                owner.getContentPane().add(new JButton("E"), BorderLayout.EAST);
            //                owner.getContentPane().add(new JButton("W"), BorderLayout.WEST);
            //                owner.getContentPane().add(slider, BorderLayout.CENTER);
            //            }
            //            else {
            //
            //            }

            owner.setSize(300, 300);
            owner.setLocationRelativeTo(null);
            owner.setVisible(true);

            return;
        }

        // final String filename = "iio_image.png";
        // final RenderedImage image = JAI.create("fileload", filename);

        if (true) {

            final String filename = "iio_image.png";
            final BufferedImage[] image = Factory_Image.getInstance().createImage("iio_image.png");
            final BufferedImage[] image1 = Factory_Image.getInstance().createImage("iio_image.png");
            final BufferedImage[] image2 = Factory_Image.getInstance().createImage("iio_image.png");

            // RenderedImage image = "// the image to be stored //";
            // RenderedOp op = JAI.create("filestore", image, filename, format);

            final JFrame jFrame = Factory_Swing.getInstance().createJFrame();
            jFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
            // jFrame.setUndecorated(true);
            // final JDialog jFrame = new JDialog();
            // jFrame.setUndecorated(true);
            // final JWindow jFrame = new JWindow();

            jFrame.setSize(400, 400);
            Helper_Swing.getInstance().centerOnScreen(jFrame, true);
            final J42JPanel_Slidable cpfJPanel_Slidable = new J42JPanel_Slidable(jFrame);

            final JPanel panelOld = new JPanel() {
                private static final long serialVersionUID = 6869111811625725233L;
                {
                    setSize(jFrame.getWidth(), jFrame.getHeight());
                    setLocation(0, 0);
                    setBackground(Color.BLUE);
                }
            };
            panelOld.add(new JButton("BLUE - OLD") {
                private static final long serialVersionUID = 5242186323886665987L;
                {
                    addActionListener(new ActionListener() {
                        @Override
                        public void actionPerformed(final ActionEvent e) {
                            cpfJPanel_Slidable.getManager().slideLeft();
                        }
                    });
                }
            });

            final JPanel panelNew = new JPanel() {
                /**
                 *
                 */
                private static final long serialVersionUID = -5637132752745390953L;

                {
                    setSize(jFrame.getWidth(), jFrame.getHeight());
                    setLocation(0, 0);
                    setBackground(Color.RED);
                }
            };
            panelNew.add(new JButton("RED - NEW") {
                /**
                 *
                 */
                private static final long serialVersionUID = 6894982633801607129L;

                {
                    addActionListener(new ActionListener() {
                        @Override
                        public void actionPerformed(final ActionEvent e) {
                            cpfJPanel_Slidable.getManager().slideRight();
                        }
                    });
                }
            });

            // final CpfJGeneric<JPanel> imagable = CpfJFactory.creatInstance_CpfJGeneric_Imagable(JPanel.class);
            // final Component imageComponent = imagable.initialize(cpfJPanel_Slidable.getBasePanel());
            // imagable.getManager(ImagableManager.class).runtime.setImage0(image[0]);

            cpfJPanel_Slidable.add(panelOld);
            cpfJPanel_Slidable.add(panelNew);
            cpfJPanel_Slidable.add(new JTree());
            cpfJPanel_Slidable.add(new JTree());
            // cpfJPanel_Slidable.addComponent(imageComponent);

            final J42JPanel_Slidable s2 = new J42JPanel_Slidable(new JFrame());

            s2.add(panelNew);
            s2.add(panelOld);
            cpfJPanel_Slidable.add(s2);

            s2.add(panelNew);
            s2.add(panelOld);
            cpfJPanel_Slidable.add(s2);

            // why is this not not needed?
            // s2.attach();
            // cpfJPanel_Slidable.attach();

            jFrame.setVisible(true);
        }

        return;
    }
}
